import Vue from 'vue'

/**
 * enable 可点击指令
 */
const enable = Vue.directive('dist-show', {
  inserted: function (el, binding, vnode) {
    if (binding.value) {
      const fn = new Function('context', binding.value)
      const show = fn(vnode.context)
      if (!show) {
        el.parentNode.removeChild(el)
      }
    }
  },
  update: function (el, binding, vnode) {
    binding.def.inserted(el, binding, vnode)
  }
})

export default enable
